﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ApiTemplateGenerate.TemplateJsAxios
{
    /// <summary>
    /// TS API方法模版
    /// 
    /// import service from '../../config'
    /// import link from '../../link'
    /// import* as common from '../../commonArgument'
    /// let ApiUrl = link.OAServiceX.APIService
    /// /**
    ///  * 分页获取数据
    ///  * @param query  body参数 interface S{ PageIndex: number;  PageSize: number;}
    ///  * @returns Arry<T> 
    ///  */
    /// export const GetPageList = async(query) => {
    ///   let responseData: any = await service({
    ///     url: ApiUrl + `/api/VersionInfo/GetPageList`,
    ///     method: 'get',
    ///     params: {query:query},
    ///     data:query,
    ///     })
    ///   return responseDataReturn
    /// }
    /// </summary>
    public class TemplateMethod
    {
        public static string Template = @"
import service from '../../config'
import link from '../../link'
let ApiUrl = link.OAServiceX.APIService
@foreach (var item in Model){
    if(!string.IsNullOrEmpty(@item.Describes)){<text>@item.Describes</text>}else{}
<text></text>
<text>export const @item.MethodName = async (@item.ParameterString) => {</text>
  <text>  let responseData = await service({</text>
    <text>    url: ApiUrl + `@item.ApiUrl`,</text>
    <text>    method: '@item.RequestMethod',;</text>
 if(!item.IsNullParam){
         if(item.IsParams){
    <text>params: @item.Params ;</text>
         }
         if(item.IsData){
    <text>data: @item.Data ;</text>
         }
}
  <text>  })</text>
  <text>  return responseData</text>
<text>}</text>
}
";
    }
}
